#include <string.h>
#include <stdio.h>
#include <malloc.h>
#include "quene.h"



void initquene(cmdquene** s,int size){
    *s = (cmdquene*)malloc(sizeof(cmdquene));
	(*s)->base=(cmd *)malloc(sizeof(cmd)*size);
	if(!(*s)->base)
		return;
	(*s)->front=0;
	(*s)->rear=0;
    (*s)->count = 0;
    (*s)->size = size;
}

void enquene(cmdquene* s,cmd* e){
	if(s->count == s->size){
	    printf("quene full\n");
	    return;
	}
	memcpy(&(s->base[s->rear]),e,sizeof(cmd));
	s->rear=(s->rear+1)%s->size;
    s->count ++;
}

void dequene(cmdquene* s,cmd* e){
	if(s->count == 0){
	    printf("quene empty\n");
        return;
	}
	memcpy(e,&(s->base[s->front]),sizeof(cmd));
	s->front=(s->front+1)%s->size;
    s->count --;
}

void destoryquene(cmdquene* s){
    if(s){
        if(s->base){
            free(s->base);
        }
        free(s);
        printf("destoryquene ok\n");
    }
}

int getquenelength(cmdquene* s){
	return s->count;
}